//
//  Network.swift
//  testDemo
//
//  Created by 张彦辉 on 2017/8/13.
//  Copyright © 2017年 张彦辉. All rights reserved.
//

import Alamofire
import SwiftyJSON

struct Network {
    static func getMovies(param:Parameters,d:@escaping (_ list:[Movie],_ hasNext:Bool)->()){
        Alamofire.request(URLs.MOVIE_PAGE, method: .get, parameters: param, encoding: URLEncoding.default, headers: nil).responseJSON { (response) in
            let json = JSON(data: response.data!)
            var movieList = [Movie]()
            let data = json["data"]
            
            for i in 0 ..< data.count {
                let m = data[i]
                let movie = Movie()
                movie.id = m["id"].stringValue
                movie.name = m["name"].stringValue
                movie.area = m["area"].stringValue
                movie.type = m["area"].stringValue
                movie.image = m["image"].stringValue
                movie.downURL = m["url"].stringValue
                movie.pwd = m["password"].stringValue
                
                movieList.append(movie)
            }
            let hasNext = json["hasNext"].boolValue
            d(movieList,hasNext)
            
        }
    }
}
